<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<link rel="stylesheet" href="css/bootstrap-3.3.7/css/bootstrap.min.css" />
<link rel="stylesheet" href="css/register.css" />
<link rel="stylesheet" href="css/listCommon.css" />
<link rel="stylesheet" href="css/evaluation.css" />
<%-- 导入面包屑 --%>
<jsp:include page="../common/nav.jsp"></jsp:include>
<style>
	.redragon-head-title{
		font-size: 20px;
		color: #2972FA;
		border-left: 4px solid #2972fa;
		padding-left: 15px;
		margin-bottom: 30px;
	}
	.ibox-content {
		border-width: 0px;
	}
	.saveBtn{
		background: #2c74fa;
		margin-left: 20px;
		border: none;
		color: #fff;
	}
	.btnBack{
		background: #ddd;
		margin-left: 20px;
		border: none;
		color: #fff;
	}
	.btn-change{
		background: #f8ac59;
		margin-left: 20px;
		border: none;
		color: #fff;
	}
	.btn-submit{
		background: #e36858;
		margin-left: 20px;
		border: none;
		color: #fff;
	}
	.form-control[disabled], .form-control[readonly], fieldset[disabled] .form-control {
		background-color: #fff;
	}
</style>
<div class="wrapper wrapper-content animated fadeInRight">

	<%-- 导入提示信息框 --%>
	<c:if test="${hint!=null&&hint!=''}">
		<jsp:include page="../common/alert/alert.jsp">
			<jsp:param value="${hint}" name="alertType"/>
			<jsp:param value="${alertMessage}" name="alertMessage"/>
		</jsp:include>
	</c:if>

	<div class="row">
		<div class="col-lg-12">
			<div class="ibox ">

				<h5><span class="redragon-head-title">出库单头信息</span></h5>
				<div class="ibox-tools">
					<i class="fa fa-chevron-up"></i>
				</div>


				<div id="ibox-content" class="ibox-content border-bottom" style="padding-bottom: 0px;">
					<form id="form" action="web/invInputHead/editInvInputHead" method="post">

						<div class="tabs-container">
							<ul class="nav nav-tabs">
								<li><a class="nav-link active" data-toggle="tab" href="#mainTab">标准信息 </a></li>
								<li><a class="nav-link" data-toggle="tab" href="#otherTab">自定义 <i class="fa fa-puzzle-piece"></i></a></li>
							</ul>
							<div id="headTabDiv" class="tab-content">

								<!-- mainTab开始 -->
								<div id="mainTab" class="tab-pane active">
									<div class="panel-body" style="padding-bottom: 0px; border-bottom: 0px;">

										<div class="row">
											<div class="col-md-6">
												<div class="form-group">
													<span>*</span>
													<label>出库单编码：</label>
													<input id="outputHeadCode" name="outputHeadCode" type="text" class="form-control" value="${requestScope.invOutputHead.outputHeadCode}" readonly>
												</div>
											</div>

											<div class="col-md-6">
												<div class="form-group">
													<span>*</span>
													<label>出库类型：</label>
													<select class="form-control" name="outputType" id="outputType">
														<option value="" selected="selected">请选择...</option>
														<c:forEach items="${requestScope.outputTypeMap}" var="outputType">
															<option value="${outputType.key}">${outputType.value}</option>
														</c:forEach>
													</select>
												</div>
											</div>
											<div class="col-md-6">
												<div class="form-group">
													<span>*</span>
													<label>出库日期：</label>
													<input id="outputDate" name="outputDate" type="date" class="form-control" value="${requestScope.invOutputHead.outputDate}">
												</div>
											</div>
											<div class="col-md-6">
												<div class="form-group">
													<span>&nbsp</span>
													<label>备注：</label>
													<input id="memo" name="memo" type="text" class="form-control" value="${requestScope.invOutputHead.memo}">
												</div>
											</div>
											<div class="col-md-6">
												<div class="form-group">
													<span>*</span>
													<label>制单人：</label>
													<input type="text" id="staffCode" name="staffCode" class="form-control" value="${requestScope.invOutputHead.staffCode}" readonly="readonly">
												</div>
											</div>
											<div class="col-md-6">
												<div class="form-group">
													<span>*</span>
													<label>制单部门：</label>
													<input type="text" id="departmentCode" name="departmentCode"  class="form-control" value="${requestScope.invOutputHead.departmentCode}" readonly="readonly">
												</div>
											</div>







											<div class="col-md-12">
												<%--<div class="form-group">--%>
												<div class="col-sm-offset-2 text-right">
													<%--<input type="button" class="btn selectBtn" data-style="expand-right" onclick="selectBtnData()" value="查询"/>--%>
													<%--<button class="btn btnBack" type="button" onclick="window.location.href='web/invInputHead/getInvInputHeadList'">返回</button>&nbsp;
                                                    <c:if test="${param.inputHeadCode==null||param.inputHeadCode==''||requestScope.invInputHead.approveStatus=='UNSUBMIT'||requestScope.invInputHead.approveStatus=='REJECT' }">
                                                        <button class="btn saveBtn" data-style="expand-right">保存</button>
                                                    </c:if>--%>

													<%--		</div>--%>
												</div>
											</div>
										</div>

										<%--<input type="hidden" id="status" name="status" value="${requestScope.invInputHead.status}">
										<input type="hidden" id="staffCode" name="staffCode" value="${requestScope.invInputHead.staffCode}">
										<input type="hidden" id="departmentCode" name="departmentCode" value="${requestScope.invInputHead.departmentCode}">
										<input type="hidden" id="inputHeadId" name="inputHeadId" value="${requestScope.invInputHead.inputHeadId}">
										<input type="hidden" name="createdDate" value="${requestScope.invInputHead.createdDate}">
										<input type="hidden" name="createdBy" value="${requestScope.invInputHead.createdBy}">
										<input type="hidden" id="version" value="${requestScope.invInputHead.version}">--%>

									</div>
								</div>
								<script>
                                    function selectBtnData() {
                                        getLineTab("${requestScope.invInputHead.inputHeadCode}");
                                    }

								</script>
								<!-- mainTab结束 -->

								<!-- otherTab开始 -->
								<div id="otherTab" class="tab-pane"></div>

								<script>
                                    $(document).ready(function(){
                                        $.ajax({
                                            type: "post",
                                            url: "web/cuxFlexFieldHead/beforeHeadFlexField",
                                            data: {"ffHeadCode": "inv_input_head"},
                                            async: true,
                                            dataType: "html",
                                            cache: false,
                                            success: function(data){
                                                if(data!=""){
                                                    $("#otherTab").html(data);
                                                    $("#attribute1").val("${requestScope.invInputHead.attribute1}");
                                                    $("#attribute2").val("${requestScope.invInputHead.attribute2}");
                                                    $("#attribute3").val("${requestScope.invInputHead.attribute3}");
                                                    $("#attribute4").val("${requestScope.invInputHead.attribute4}");
                                                    $("#attribute5").val("${requestScope.invInputHead.attribute5}");
                                                    $("#attribute6").val("${requestScope.invInputHead.attribute6}");
                                                    $("#attribute7").val("${requestScope.invInputHead.attribute7}");
                                                    $("#attribute8").val("${requestScope.invInputHead.attribute8}");
                                                    $("#attribute9").val("${requestScope.invInputHead.attribute9}");
                                                    $("#attribute10").val("${requestScope.invInputHead.attribute10}");
                                                }
                                            },
                                            error: function(XMLHttpRequest, textStatus, errorThrown){
                                                redragonJS.alert("加载自定义辅助字段错误");
                                            }
                                        });
                                    });
								</script>
								<!-- otherTab结束 -->

							</div>
						</div>



						<!-- tab 开始 -->
						<div class="row">
							<div class="col-lg-12">
								<div class="ibox ">
									<div>
										<%--<h5 class="redragon-head-title">入库单行信息</h5>
										<div class="ibox-tools">
										</div>--%>
											<div id="ibox-content" class="ibox-content border-bottom" style="padding-bottom: 0px;">
												<div class="formTitle">
													物资信息
													<button type="button" class="btn  addMetarial" onclick="getMaterialListByName()" data-toggle="modal" data-target="#addMetarial">添加物资</button>
												</div>
											</div>
									</div>
									<div class="form-group">
										<div id="ibox-content1" class="ibox-content border-bottom" style="padding-bottom: 0px;">
											<div class="tabs-container">
												<ul class="nav nav-tabs">
													<li><a class="nav-link active" data-toggle="tab" href="#lineTab" onclick="getLineTab('${requestScope.invInputHead.inputHeadCode}')">行列表</a></li>
												</ul>


												<div id="lineTab" class="tab-pane">
													<div class="panel-body" style="padding-bottom: 0px; border-bottom: 0px;">

														<div class="table-responsive">
															<table id = "eee" class="table table-stripped table-hover table-bordered border-top">
																<thead id="InvInput">

																</thead>

															</table>

														</div>

													</div>
												</div>

												<div id="selectPOLineModal"></div>
												<div id="addLineModal"></div>

												<div class="form-group">
													<input id="JSONText" name="JSONText" class="form-control" type="hidden" value=""/>
												</div>

											</div>
										</div>
									</div>
								</div>
							</div>
						</div>
						<!-- tab 结束 -->
						<%--<div class="col-sm-offset-2 text-right">
							<button class="btn btnBack" type="button" onclick="window.location.href='web/invInputHead/getInvInputHeadList'">返回</button>&nbsp;
							<c:if test="${param.inputHeadCode==null||param.inputHeadCode==''||requestScope.invInputHead.approveStatus=='UNSUBMIT'||requestScope.invInputHead.approveStatus=='REJECT' }">
								<button class="btn saveBtn" data-style="expand-right">保存</button>
							</c:if>
						</div>--%>
						<div class="formTitle">签批流程设置</div>
						<div class="trackInfomation">
							<div class="row">
								<div class="col-md-12">
									<div class="form-group">
										<span>*</span>
										<label>选择流程审批人：</label>
										<input id="nextapproverid" name="nextapproverid" type="text" class="form-control" >
										<input id="nextapprovername" name="nextapprovername" type="text" class="form-control" placeholder="请选择人员" data-toggle="modal" >
									</div>
								</div>
							</div>
						</div>
						<div class="trackSubmit">
							<button type="button" onclick="save()">保存</button>
							<button type="button" onclick="window.location.href='web/invOutputHead/getInvOutputHeadList'">返回</button>
						</div>
					</form>
				</div>
			</div>
		</div>
	</div>
</div>



<div  class="modal " id="addDiv1" tabindex="-1" role="dialog" >
	<div class="modal-dialog" role="document" style="margin-top:50px;">
		<div class="modal-content" style="padding: 0 20px">
			<div class="modal-header">
				<h4 class="modal-title" id="ora_modal_title"></h4>
				<button type="button" class="close" data-dismiss="modal" aria-label="Close" onclick="close()"><span aria-hidden="true">&times;</span></button>
			</div>
			<div class="modal-body">
				<c:import url="/web/hrDepartment/getHrDepartmentTreeReadOnly" charEncoding="utf-8"></c:import>
			</div>
		</div>
	</div>
</div>

<!--选择下一步审批人模态框-->
<div id="approverSelect" class="modal comTreemodal" tabindex="-1" role="dialog">
	<div class="modal-dialog" role="document">
		<div class="modal-content" >
			<div class="modal-body">
				<div class="row">
					<div class="col-sm-6">
						<%--<c:import url="/web/hrDepartment/getHrDepartmentTreeReadOnly" charEncoding="utf-8"></c:import>--%>
						<div class="ibox ">
							<div class="ibox-content border-bottom">
								<div class="input-group col-sm-12">
									<div class="input-group-addon bg-info">
										<i class="fa fa-search"></i>
									</div>
									<input type="text" class="form-control" id="searchTree1" placeholder="输入查询条件...">
								</div>
								<div class="hr-line-dashed"></div>
								<div id="jstree_div1" style="overflow: auto;"></div>
							</div>
						</div>
					</div>
					<div id="relateListDiv" class="col-sm-6"></div>
				</div>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-primary" id="submitSelect">确定</button>
			</div>
		</div>
	</div>
</div>


<!-- pay模式对话框 -->
<div id="headModal"></div>
<!-- 会计分录 -->
<div id="voucherEntryModal"></div>

<!-- workflow -->
<script src="js/workflow.js"></script>
<div id="approveWorkflowModal"></div>
<jsp:include page="pop/outputTreeModal.jsp"></jsp:include>
<!-- select2 -->
<script src="js/plugins/select2/select2.full.min.js"></script>

<!-- editPage -->
<script src="js/editPage.js"></script>

<script src="js/plugins/chosen/chosen.jquery.js"></script>

<script src="css/bootstrap-3.3.7/js/address.js" type="text/javascript" charset="utf-8"></script>
<script src="js/jquery-ui.js"></script>
<script src="js/bootstrap.js/bootstrap.min.js"></script>

<script src="module/webuploader/mywebuploader.js"></script>
<script src="module/webuploader/webuploader.js"></script>

<!-- jsTree -->
<link href="css/plugins/jsTree/style.min.css" rel="stylesheet">
<script src="js/plugins/jsTree/jstree.min.js"></script>

<link href="css/plugins/chosen/bootstrap-chosen.css" rel="stylesheet">
<link href="module/webuploader/webuploader.css" rel="stylesheet">

<script>
    $(document).ready(function() {

        //初始化select2
        $('.select2').select2({width: "100%"});

        //设置日期插件
       /* $('#outputDate').datepicker({
            todayBtn : "linked",
            keyboardNavigation : true,
            forceParse : true,
            calendarWeeks : false,
            autoclose : true,
            format: 'yyyy-mm-dd',
            language: 'zh-CN',
        });
*/


        //表单
        var l = $('.ladda-button-demo').ladda();

        l.click(function() {
            $("#form").valid();
            //l.ladda('stop');
        });

        $("#form").validate({
            rules : {

                inputType : {
                    required : true,
                },
                inputManner : {
                    required : true,
                },
                warehouseCode : {
                    required : true,
                },

                inputSourceType : {
                    required : true,
                },
                /*inputSourceHeadCode : {
                    required : true,
                },
                */
                inputDate : {
                    required : true,
                },
            },
            submitHandler: function(form) {
                var submitFlag = "Y";

                //入库类型选择杂项入库效果
                if($("#inputType").val()=="OTHER_IN"){
                }else{
                    if($("#inputSourceType").val()==""){
                        redragonJS.alert("送货方式必填");
                        submitFlag = "N";
                        return false;
                    }

                    if($("#inputSourceHeadCode").val()==""){
                        redragonJS.alert("来源头编码必填");
                        submitFlag = "N";
                        return false;
                    }
                    if($('#inputManner').val()==""){
                        redragonJS.alert("入库方式必选");
                        submitFlag = "N";
                        return false;
                    }
                }

                //提交
                if(submitFlag=="Y"){

                    var tr;
                    var dataArray = new Array();

                    for(var j = 1;j < document.getElementById("eee").rows.length;j++){
                        var invNum = $("#invNum"+j).val();
                        var invLoss = $("#invLoss"+j).val();
                        var invGive = $("#invGive"+j).val();
                        var invattachedMemo = $("#invattachedMemo"+j).val();




                        date = new Object();
                        tr = document.getElementById("eee").rows[j];
                        date.id = tr.childNodes[0].innerHTML;
                        date.material_code = tr.childNodes[1].innerHTML;
                        date.price = tr.childNodes[4].innerHTML;
                        date.standard_unit = tr.childNodes[5].innerHTML;
                        date.allPrice = tr.childNodes[6].innerHTML;
                        date.input_quantity = invNum;
                        date.loss = invLoss;
                        date.attached = invGive;
                        date.attached_memo = invattachedMemo;

                        dataArray.push(JSON.stringify(date));

                    }

                    //document.getElementById('JSONText').value = dataArray.toString();
                    // $("#JSONText").append(dataArray.toString());
                    $('#JSONText').val(dataArray.toString());

                    l.ladda('start');
                    form.submit();
                }
            }
        });


        //------------------------------------------------------

        $("#nextapprovername").on("click",function(){
            $('#approverSelect').modal('show');
            $('.show').removeClass("modal-backdrop");
            addTree();
        });
        $("#submitSelect").on("click",function(){
            debugger;
            var apprcodes = "";//选中参与者编码串
            var apprnames = "";//选中参与者名称串
            var checkedIds = $("#userSelect").find("input"), ids = [];
            for (var i = 0; checkedIds && i < checkedIds.length; i++) {
                var obj = $("#userSelect").find("input").eq(i);
                if (obj.is(":checked")) {
                    ids.push(obj.attr("id"));
                }
            }
            console.log(ids);
            if(ids.length>0){
                $.each(ids, function (index, item) {
                    apprcodes+=item.split('_')[0]+',';
                    apprnames+=item.split('_')[1]+',';
                });
                $('#nextapproverid').val(apprcodes.substring(0,apprcodes.length-1));
                $('#nextapprovername').val(apprnames.substring(0,apprnames.length-1));
                $('#approverSelect').modal('hide');
            }else{
                redragonJS.alert("请选择流程参与者");
            }
        });

    });







    //重新创建凭证分录
    function autoCreateVoucherEntry(headCode){
        $.ajax({
            type: "post",
            url: "web/invInputHead/autoCreateVoucherEntry",
            data: {"headCode": headCode, "inputType": $("#inputType").val()},
            async: false,
            dataType: "json",
            cache: false,
            success: function(data){
                if(data.errCode==0){
                    redragonJS.alert("重新生成分录成功");
                }else{
                    redragonJS.alert(data.errMsg);
                }
            },
            error: function(XMLHttpRequest, textStatus, errorThrown){
                redragonJS.alert(textStatus);
            }
        });
    }

    //提交审批
    function submitData(){
        var submitFlag = "Y";

        if($("#lineTab tbody tr").length==0){
            submitFlag = "N";
            redragonJS.alert("至少新增一行后，才能提交数据");
        }

        //提交
        if(submitFlag=="Y"){
            window.location.href='web/invInputHead/updateApproveStatus?code=${requestScope.invInputHead.inputHeadCode}&approveStatus=SUBMIT';
        }
    }

    //审批通过
    function approveData(confirmFlag){
        if(confirmFlag=="N"){
            window.location.href='web/invInputHead/updateApproveStatus?code=${requestScope.invInputHead.inputHeadCode}&approveStatus=APPROVE';
        }else{
            redragonJS.confirm("确认审批通过？", function(){
                window.location.href='web/invInputHead/updateApproveStatus?code=${requestScope.invInputHead.inputHeadCode}&approveStatus=APPROVE';
            });
        }
    }

    //审批驳回
    function rejectData(){
        //redragonJS.confirm("确认审批驳回？", function(){
        window.location.href='web/invInputHead/updateApproveStatus?code=${requestScope.invInputHead.inputHeadCode}&approveStatus=REJECT';
        //});
    }

    //数据变更
    function alterData(){
        redragonJS.confirm("确认变更数据？数据变更后将产生变更历史信息！", function(){
            window.location.href='web/invInputHead/updateApproveStatus?code=${requestScope.invInputHead.inputHeadCode}&approveStatus=UNSUBMIT';
        });
    }




    //为外面的盒子绑定一个点击事件
    $("#uploadImgBtn0").click(function(e){

        imagesUpload(e);
    })

    function imagesUpload(e){

        var cid=e.currentTarget.id;
        var s=cid.substr(cid.length-1,1);

        /*
        1、先获取input标签
        2、给input标签绑定change事件
        3、把图片回显
         */
        //1、先回去input标签
        var $input = $("#file"+s+"");
        //2、给input标签绑定change事件
        $input.on("change" , function(){
            //补充说明：因为我们给input标签设置multiple属性，因此一次可以上传多个文件
            //获取选择图片的个数
            var files = this.files;

            // 通过FormData将文件转成二进制数据
            // 文件元素
            var file = document.querySelector('[type=file]');
            // 通过FormData将文件转成二进制数据
            var formData = new FormData();
            for(var i = 0;i<files.length;i++){
                formData.append("imgs", files[i]);
            }
            var ss=formData.get("fileImage[]");

            $.ajax({
                type: "post",
                url:  "<%=basePath%>web/hrStaff/file",
                data: formData,
                dataType: "json",
                processData: false, // 告诉jQuery不要去处理发送的数据
                contentType: false, // 告诉jQuery不要去设置Content-Type请求头
                xhrFields:{withCredentials:true},
                async: true,    //默认是true：异步，false：同步。
                success: function (data) {

                    if(data!=""){
                        var url="";
                        var html = "";
                        for (var i=0;i<data.length;i++){
                            url+=data[i]+",";
                            html+="<a target='_blank' href='"+data[i]+"'>"+data[i].substr(data[i].lastIndexOf("/") + 1)+"</a>\n"
                        }
                        $("#file").val(url);
                        $("#showFile").html(html);
                    }

                },
                error: function(XMLHttpRequest, textStatus, errorThrown){
                    redragonJS.alert(textStatus);
                },
            });
        })
    }





    //为外面的盒子绑定一个点击事件
    $("#uploadTestingFileBtn0").click(function(e){

        testImagesUpload(e);
    })

    function testImagesUpload(e){

        var cid=e.currentTarget.id;
        var s=cid.substr(cid.length-1,1);

        /*
        1、先获取input标签
        2、给input标签绑定change事件
        3、把图片回显
         */
        //1、先回去input标签
        var $input = $("#testingFile"+s+"");
        //2、给input标签绑定change事件
        $input.on("change" , function(){
            //补充说明：因为我们给input标签设置multiple属性，因此一次可以上传多个文件
            //获取选择图片的个数
            var testingFiles = this.files;
            alert(testingFiles);
            alert(testingFiles.length);
            // 通过FormData将文件转成二进制数据
            // 文件元素
            var file = document.querySelector('[type=file]');
            // 通过FormData将文件转成二进制数据
            var formData = new FormData();
            for(var i = 0;i<testingFiles.length;i++){
                formData.append("imgs", testingFiles[i]);
            }
            var ss=formData.get("fileImage[]");

            $.ajax({
                type: "post",
                url:  "<%=basePath%>web/hrStaff/file",
                data: formData,
                dataType: "json",
                processData: false, // 告诉jQuery不要去处理发送的数据
                contentType: false, // 告诉jQuery不要去设置Content-Type请求头
                xhrFields:{withCredentials:true},
                async: true,    //默认是true：异步，false：同步。
                success: function (data) {

                    if(data!=""){
                        var url="";
                        var html = "";
                        for (var i=0;i<data.length;i++){
                            url+=data[i]+",";
                            html+="<a target='_blank' href='"+data[i]+"'>"+data[i].substr(data[i].lastIndexOf("/") + 1)+"</a>\n"
                        }
                        $("#testingFile").val(url);
                        $("#showFile1").html(html);
                    }

                },
                error: function(XMLHttpRequest, textStatus, errorThrown){
                    redragonJS.alert(textStatus);
                },
            });
        })
    }

</script>
<script>

    function getMaterialListByName() {

        getSelectOutputModal();
    }


    function getSelectOutputModal(page){
        $('#selectPODiv').modal('hide');
        redragonJS.loading("ibox-content");
        $.ajax({
            type: "post",
            url: "web/invOutputHead/getOutputStock",
            data: {"deliveryCode": $("#deliveryCode").val(), "deliveryName": $("#deliveryName").val(), "page": page,
                "supplier": $("#supplier").val()},
            async: false,
            dataType: "html",
            cache: false,
            success: function(data){
                redragonJS.removeLoading("ibox-content");
                if(data!=""){
                    $("#headModal").html(data);
                    $('#selectPODiv').modal('show');
                    $(".modal-backdrop").remove();
                }
            },
            error: function(XMLHttpRequest, textStatus, errorThrown){
                redragonJS.alert(textStatus);
            }
        });
    }

</script>
<script>
	/*function selCostSubject() {
        $('#outputTreeDiv').modal('show');
        $(".modal-backdrop").remove();
    }*/



    //封装请求后台参数
    function getSubmitInfo() {
        var id = $("#id").val();
        var status = $("#status").val();
        var nextapproverid = $("#nextapproverid").val();
        var data = {};
        data.outputHeadId = id;
        data.outputHeadCode = $("#outputHeadCode").val();
        data.outputType = $("#outputType").val();
        data.outputDate = $("#outputDate").val();
        data.memo = $("#memo").val();
        data.staffCode = $("#staffCode").val();
        data.departmentCode = $("#departmentCode").val();
        data.status = status == "" ? "0" : status;
        data.nextapproverid = nextapproverid;
        var subs = [];
        var subSize = 1;
        for(var i = 1; i <= subSize; i ++){
            var sub = {};
            sub.materialCode = $("#material_code").text();
            sub.standard = $("#standard").text();
            sub.materialName = $("#materialName").text();
            sub.outputQuantity = $("#numCount").text();
           /* sub.outputLineId = $("#subId" + i).text();
            sub.outputHeadCode = data.outputHeadCode;
            sub.materialId = $("#subModelNumber" + i).text();
            sub.materialCode = $("#subCode" + i).text();
            sub.standard = $("#subBrand" + i).text();
            sub.materialName = $("#subName" + i).text();
            sub.categoryName = $("#subType" + i).text();
            sub.standard = $("#subModelNumberText" + i).text();
            sub.unit = $("#subUnit" + i).text();
            sub.outputQuantity = $("#subNumber" + i).text();
            sub.status = status == "" ? "0" : status;
            sub.memo = $("#subRemark" + i).text();*/
            subs.push(sub);
        }
        data.invOutputLines = subs;

        return data;
    }

    function save() {

            $.ajax({
                url : "web/invOutputHead/save",
                contentType : "application/json",
                dataType : 'json',
                data : JSON.stringify(getSubmitInfo()),
                type:'post',
                async : true,
                success : function(data) {
                    if(data.code == 1) {
                        redragonJS.alert("操作成功!");
                        setTimeout(function(){
                            window.location.href='web/invOutputHead/getInvOutputHeadList'
                        },1000);
                    } else {
                        redragonJS.alert(data.msg);
                    }
                }
            });

    }




</script>
<script>
    //ajax获取关联列表
    function getRelateListAjax(id,page){
        redragonJS.loading("relateListDiv");
        $.ajax({
            type: "post",
            url: "web/hrStaffDepartmentR/getFlowSelectRelateListAjax",
            data: {"departmentId": id,"page":page==null?1:page},
            async: false,
            dataType: "html",
            cache: false,
            success: function(data){
                redragonJS.removeLoading("relateListDiv");
                if(data!=""){
                    $("#relateListDiv").html(data);
                }
            },
            error: function(XMLHttpRequest, textStatus, errorThrown){
                redragonJS.alert(textStatus);
            }
        });
    }


    function getAddRelateModal(nodeId, id){
        $.ajax({
            type: "post",
            url: "web/hrStaffDepartmentR/getHrStaffDepartmentR",
            data: {"departmentId": nodeId,"sdId": id},
            async: false,
            dataType: "html",
            cache: false,
            success: function(data){
                if(data!=""){
                    $("#addModal").html(data);
                    $('#addDiv1').modal('show');
                    $("div").removeClass("modal-backdrop show");
                }
            },
            error: function(XMLHttpRequest, textStatus, errorThrown){
                redragonJS.alert(textStatus);
            }
        });
    }

    $('#jstree_div1').jstree({
        'core' : {
            "themes" : {
                "stripes" : false,//背景是否显示间纹
                "dots": false,//是否显示树连接线
                "icons": true,//是否显示节点的图标
                "ellipsis": true,//节点名过长时是否显示省略号
            },
            'multiple' : false,  // 可否多选
            'dblclick_toggle': true,   //允许tree的双击展开
            'expand_selected_onload': false,
            'data' : {
                'url': 'web/hrDepartment/getHrDepartmentTreeData',
                'dataType': 'json',
                'data': function (node) { // 传给服务端点击的节点
                    return { 'nodeId': node.id };
                },
                success: function (data) {

                    if(data.id==""){
                        $("#jstree_div1").html("");
                    }else{
                        $("#addRootButton").hide();
                    }
                }
            },
            "check_callback" : true,
        },
        'plugins': ["state",'types','themes','search','unique','changed'],
        "types" : {
            "default" : {
                'icon' : 'fa fa-folder'
            },
            "root" : {
                "icon" : 'fa fa-home fa-lg',
            },
            "node" : {
                'icon' : 'fa fa-folder'
            },
        },
        'checkbox': {
            // 去除checkbox插件的默认效果
            'tie_selection': false,
            'keep_selected_style': true,
            'whole_node': false,
            'three_state': false,
        }
    })
    //单击事件
        .on('click.jstree', function(event) {

            getRelateListAjax(getTreeSelectNodeId1(),null);
        })


    //设置查询功能
    var to = false;
    $('#searchTree1').keyup(function() {
        if (to) {
            clearTimeout(to);
        }
        to = setTimeout(function() {
            var v = $('#searchTree1').val();
            $('#jstree_div1').jstree(true).search(v);
        }, 250);
    })
    //返回选择的节点id
    function getTreeSelectNodeId1(){
        var selectId = $("#jstree_div1").jstree(true).get_selected();
        return selectId.toString();
    }
    //返回选择的节点type
    function getTreeSelectNodeType1(){
        return $("#jstree_div1").jstree(true).get_type(getTreeSelectNodeId1());
    }



    function addTree() {

        var element_id = "";
        //jstree单击事件
        var selectedNodeId = -1;
        function clickJsTree(nodeId){
            selectedNodeId = nodeId;
            var selectText =  $("#jstree_div1").jstree(true).get_text(selectedNodeId);
            $('#'+element_id).val(selectText);
            $('#addDiv1').modal('hide');
        }
        function dblclickJsTree(nodeId){
            if(selectedNodeId!=nodeId){
                selectedNodeId = nodeId;
                var selectText =  $("#jstree_div1").jstree(true).get_text(selectedNodeId);
                $('#'+element_id).val(selectText);
                $('#addDiv1').modal('hide');
            }
        }
        //默认jstree选择
        function stateReadyJsTree(nodeId){
            selectedNodeId = nodeId;
        }
        function close() {
            $("#addDiv1").modal('hide').removeClass("show");
        }
    }

</script>
